<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../query.header.jsp"%>
<style type="text/css">
#_mapSelectDiv {
	height: 400px;
	width: 600px;
	border: 1px solid #CCCCCC;
	overflow:hidden;
}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=tmKLDQePokgC7m0EyDmIYFal"></script>
<script type="text/javascript">
var _selectedPoint = {};
var _map;

$("#_mapSelectDiv").ready(function() {
	_map = new BMap.Map("_mapSelectDiv");
	_map.centerAndZoom("成都",12);	// 初始化地图,设置城市和地图级别。
	_map.enableScrollWheelZoom();	//启用滚轮放大缩小
	_map.addEventListener("click", function(e){
		//_selectedPoint.longitude = e.point.lng;
		//_selectedPoint.latitude = e.point.lat;
		_getLocationAddress(e.point.lng, e.point.lat);
	});
});

function _createMarker() {
	_map.clearOverlays();
	var pt = new BMap.Point(_selectedPoint.longitude, _selectedPoint.latitude)
	var marker1 = new BMap.Marker(pt);  // 创建标注	
	_map.addOverlay(marker1);

	//创建信息窗口
	var html = "<p>经度:" + _selectedPoint.longitude + ", 纬度:" + _selectedPoint.latitude + "</p>";
	html = html + "<p>" + _selectedPoint.locationAddress + "</p>";
	var infoWindow = new BMap.InfoWindow(html);
	marker1.addEventListener("click", function(){this.openInfoWindow(infoWindow);});
	_map.openInfoWindow(infoWindow,pt); //开启信息窗口
}

function _beforePointConfirm(callback) {
	if (_selectedPoint.longitude == undefined || _selectedPoint.latitude == undefined) {
		$.alert("请选择座标！");
		return false;		
	}
	callback(_selectedPoint);
	return true;
}

function _getLocationAddress(longitude, latitude) {
	var url = ctx + "/android/address.json?longitude=" + longitude + "&latitude=" + latitude;
	$.ajax({
		type: "GET",
		cache: false,
		url: url,
		dataType: "json",
		success: _parseLocation,
		error:function(x, message){
			$.alert(message);
		}  
	});	
}

function _parseLocation(data) {
	if (!data.succeed) {
		$.alert(data.message);
		return;
	}
	_selectedPoint = data.data;
	_createMarker();
}

</script>

<div id="_mapSelectDiv">
</div>
